import Vue from "vue"
import VueRouter from "vue-router"
Vue.use(VueRouter)

// 防止点击自身路由出错
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
}

const routes = [
  {
    component: () => import("@/layout/index"),
    name: "layout",
    path: "/",
    redirect: '/login',
    children: [
      {
        component: () => import("@/views/staffCenter/index"),
        name: "StaffCenter",
        path: "/staff-center",
        meta: {
          title: '人员管理'
        }
      },
      {
        component: () => import("@/views/staffCenter/StaffForm/index"),
        name: "StaffForm",
        path: "/staff-center/edit/:staff_id",
        meta: {
          title: '编辑员工信息'
        }
      },
      {
        component: () => import("@/views/staffCenter/StaffForm/index"),
        name: "StaffForm",
        path: "/staff-center/create",
        meta: {
          title: '新建员工信息'
        }
      },
      {
        component: () => import("@/views/staffCenter/StaffForm/index"),
        name: "StaffForm",
        path: "/staff-center/detail/:staff_id",
        meta: {
          title: '员工信息详情'
        }
      },
    ]
  },
  {
    component: () => import("@/views/login"),
    name: "Login",
    path: "/login",
    meta: {
      title: '用户登录'
    }
  },
  {
    component: () => import("@/views/register"),
    name: "Register",
    path: "/register",
    meta: {
      title: '用户注册'
    }
  },
]

const router = new VueRouter({
  routes
})

export default router
